package com.example.spring.boot.rabbitmq.controller;

import com.example.spring.boot.rabbitmq.constant.SimpleQueueConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * SimpleQueueController
 * </p>
 *
 * @author weixin
 * @date 2023/3/28 19:39
 */
@RestController
@RequestMapping("/work/")
public class SimpleQueueController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendSimple")
    public void send() {
        for (int i = 0; i < 50; i++) {
            String message = "工作消息" + i;
            rabbitTemplate.convertAndSend(SimpleQueueConstant.SIMPLE_WORK_QUEUE, message);
            System.out.println("生产者发送消息:" + message + "成功");
        }
    }
}
